package com.control.qct.businesssteward.activity;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Gravity;
import android.view.View;
import android.widget.NumberPicker;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.control.qct.businesssteward.R;
import com.control.qct.businesssteward.adapter.MemberStatisticAdapter;
import com.control.qct.businesssteward.base.BaseActivity;
import com.control.qct.businesssteward.model.MemberStatisticModel;
import com.control.qct.businesssteward.costom.NumberPictureDivider;
import com.control.qct.businesssteward.model.StoreModel;
import com.control.qct.businesssteward.utils.PopShopSelectUtils;
import com.control.qct.businesssteward.utils.PopUtils;
import com.control.qct.businesssteward.utils.TextContentUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/12/26 0026.
 */

public class MemberStatisticActivity extends BaseActivity implements PopShopSelectUtils.ICallbackStoreListener{
    @BindView(R.id.tv_member_saleroom_total)
    TextView mTvMemberSaleroomTotal;
    @BindView(R.id.tv_all_saleroom)
    TextView mTvAllSaleroom;
    @BindView(R.id.tv_all_sale_num)
    TextView mTvAllSaleNum;
    @BindView(R.id.tv_today_newly_member_num)
    TextView mTvTodayNewlyMemberNum;
    @BindView(R.id.tv_week_newly_member_num)
    TextView mTvWeekNewlyMemberNum;
    @BindView(R.id.tv_month_newly_member_num)
    TextView mTvMonthNewlyMemberNum;
    @BindView(R.id.tv_all_member_num)
    TextView mTvAllMemberNum;
    @BindView(R.id.rv_member_statistical)
    RecyclerView mRvMemberStatistical;


    private List<MemberStatisticModel> mMemberStatisticModelList;
    String content[] = {"今日", "本周", "本月"};
    private PopShopSelectUtils mPopShopSelectUtils;

    public MemberStatisticActivity() {
        super(R.layout.activity_member_statistic);
    }

    @Override
    protected void initView() {
        setLeftIcon(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        setTitle("会员统计");
        mPopShopSelectUtils = new PopShopSelectUtils();
        mPopShopSelectUtils.registerListener(this, mNetProtocol, this,1);
        setRightIcon("筛选", new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mPopShopSelectUtils.setSingleBottomPop(MemberStatisticActivity.this, R.id.rv_member_statistical,"");
            }
        });
        mMemberStatisticModelList = new ArrayList<>();
        for (int i = 0; i < 6; i++) {
            mMemberStatisticModelList.add(new MemberStatisticModel());
        }
        mRvMemberStatistical.setLayoutManager(new LinearLayoutManager(this));
        mRvMemberStatistical.setAdapter(new MemberStatisticAdapter(mMemberStatisticModelList));

        TextContentUtils.getInstance(this).setTextSize(mTvAllSaleroom, "5851.21");
    }

    @OnClick(R.id.tv_member_saleroom_total)
    public void onViewClicked() {
        setCheckPopBottom();
    }

    private int selectId;
    private int contentId;

    /**
     * 设置底部弹窗
     */
    private void setCheckPopBottom() {
        View view = View.inflate(this, R.layout.pop_member_statistic_day_select, null);
        final PopupWindow pop = PopUtils.getInstance().getBottomPop(this, view);
        TextView tvSure = view.findViewById(R.id.tv_sure);
        TextView tvCancel = view.findViewById(R.id.tv_cancel);
        NumberPicker npDayype = view.findViewById(R.id.np_day_type);
        npDayype.setDisplayedValues(content);
        //设置不可编辑
        npDayype.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
        NumberPictureDivider.getInstance().setNumberPickerDividerColor(npDayype, android.R.color.transparent);
        npDayype.setMinValue(0);
        npDayype.setMaxValue(content.length - 1);
        npDayype.setValue(contentId);
        npDayype.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
            @Override
            public void onValueChange(NumberPicker numberPicker, int oldId, int newId) {
                selectId = newId;
            }
        });
        tvCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                pop.dismiss();
            }
        });
        tvSure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                contentId = selectId;
                mTvMemberSaleroomTotal.setText(content[contentId] + "会员销售合计(元)");
                pop.dismiss();
            }
        });
        //设置PopupWindow显示位置
        pop.showAtLocation(this.findViewById(R.id.rv_member_statistical), Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL,
                0, 0);

    }

    @Override
    public void onSure(String storeId, String storeName) {

    }
}
